<?php
/**
 * Created by Shauan Andrade.
 * User: shauan
 * Date Time: 19/05/13 | 13:12
 * Project: yonkou
 */
App::uses('AppHelper','View/Helper');
class FunctionHelper extends AppHelper {

    public function Situacao($value = null)
    {
        $class = '';
        if(!empty($value))
        {
            switch($value)
            {
                case 1:
                    $class = 'green';
                    break;
                case 2:
                    $class = 'blue';
                    break;
                case 3:
                    $class = 'magenta';
                    break;
                case 4:
                    $class = 'red';
                    break;
            }
        }

        return $class;
    }

    public function DateFormat($value = array())
    {
       $date = '';
       $return_date = '';
       if(!empty($value) && is_array($value))
       {
           $date = $value['date'];
           $separator = isset($value['separator']);
           $separator = empty($separator)? '-' : $separator;
           list($day,$months,$year) = explode($separator,$date);
           $day = $day <= 31 ? $day : 00;
           $months = $months <= 12 ? $months : 00;
           $year = strlen($year) == 4 || strlen($year) == 2  ? $year : 0000;

           $months_ext = array(array('0'=>'','01'=>'Jan','02'=>'Fev','03'=>'Mar','04'=>'Abr','05'=>'Mai','06'=>'Jun','07'=>'Jul','08'=>'Ago','09'=>'Set','10'=>'Out','11'=>'Nov','12'=>'Dez'),array('0'=>'','01'=>'Janeiro','02'=>'Fevereiro','03'=>'Mar&ccedi;o','04'=>'Abril','05'=>'Maio','06'=>'Junho','07'=>'Julho','08'=>'Agosto','09'=>'Setembro','10'=>'Outubro','11'=>'Novembro','12'=>'Dezembro'));

           $week_ext = array(array('1'=>'Seg','2'=>'Ter','3'=>'Qua','4'=>'Qui','5'=>'Sex','6'=>'Sab','0'=>'Dom'),array('1'=>'Segunda','2'=>'Ter&ccedil;a','3'=>'Quarta','4'=>'Quinta','5'=>'Sexta','6'=>'Sábado','0'=>'Domingo'));
           $weekDay = date("w", mktime(0,0,0,$months,$day,$year) );
           if($value['type'] == 1)
           {
               $return_date = $months_ext[1][$months].' '.$day.', '.$year;
           }
           elseif($value['type']=='DW')
           {
               $return_date = $week_ext[1][$weekDay];
           }
           elseif($value['type']== 2)
           {
               $return_date = $day.'/'.$months.'/'.$year;
           }
       }
        return $return_date;
    }

    public function Status($valor)
    {
        $_status = '';
        if(empty($valor))
        {
            $_status = '0';
        }
        switch($valor)
        {
            case 0:
                $_status = '<span class="label help-block text-center label-important">Desativado</span>';
                break;
            case 1:
                $_status = '<span class="label help-block text-center label-success">Ativo</span>';
                break;
            default:
                $_status = '<span class="label help-block text-center label-inverse">ERROR STATUS</span>';
                break;
        }
        return $_status;
    }

    public function Active($active)
    {
        if(isset($active))
        {
            return $active;
        }
        return null;
    }

    public function limiteString($text,$num)
    {
        if(strlen($text)<=$num)
        {
            return  $text;
        }
        else
        {
            $y=substr($text,0,$num) . '...';
            return $y;
        }
    }
}
